import 'package:permission_handler/permission_handler.dart';
import 'package:flutter_base_app/export.dart';

class PermissionUtils {
  PermissionUtils._();

  //权限必须排队请求，不然会出问题
  static Future<void> launchApp() async {
    try {} catch (e) {
      LogUtils.e("launchApp error = $e");
    }
    try {
      //再次请求推送权限
      await requestPushPermission();
    } catch (e) {
      LogUtils.e("launchApp error = $e");
    }
  }

  static Future<bool> requestCameraPermission() async {
    LogUtils.i("requestCameraPermission start");
    final result = await Permission.camera.request();
    LogUtils.i("requestCameraPermission result = $result");
    return result.isGranted;
  }

  //推送权限
  static Future<bool> requestPushPermission() async {
    LogUtils.i("requestPushPermission start  ");
    // 请求权限
    final result = await Permission.notification.request();
    LogUtils.i("requestPushPermission result = $result");
    if (result.isPermanentlyDenied) {
      // 用户永久拒绝，引导至设置
      // openAppSettings();
    }
    return result.isGranted;
  }
}
